<template>
	<view style="padding: 15px;">
		
		<u-form >
			<u-form-item label="token">
				<u-input type="text" border v-model="token" placeholder="请输入token" />
			</u-form-item>
		 	<u-button style="margin: 5px 5px 5px 45px;" size="medium" type="primary" @click="startSocket">连接</u-button>
			<u-button style="margin: 5px 0 5px;" size="medium" type="success" @click="disconnect">断开连接</u-button>
			<u-form-item label="消息">
				<u-input type="text" maxlength="14000" border v-model="publicMsg" placeholder="请输入广播小" />
			</u-form-item>
			<u-button style="margin: 5px 0 5px 45px;" size="medium" type="info" @click="publicSend">广播消息</u-button>
			<u-form-item label="token">
				<u-input type="text" border v-model="usertoken" placeholder="请输入目标用户token" />
			</u-form-item>
			<u-form-item label="消息">
				<u-input type="text" maxlength="14000" border v-model="userMsg" placeholder="请输入消息" />
			</u-form-item>
			<u-button style="margin: 5px 0 5px 45px;" size="medium" type="warning" @click="sendusermsg">发送消息</u-button>
		</u-form>
		
		<view>
			用户消息：{{suserMsg}}
		</view>
		<view>
			广播消息：{{spublicMsg}}
		</view>
		
	</view>
</template>

<script>
	export default {
		data() {
			return {
				token: null,
				publicMsg: null,
				usertoken: null,
				userMsg: null
			}
		},
		onLoad() {

		},
		computed: {
			vals() {
				return this.$store.state.val
			}
		},
		methods: {
			startSocket() {
				this.$store.commit("startSocket", this.token)
			},
			publicSend() {
				this.$store.commit("publicSend", this.publicMsg)
			},
			sendusermsg() {
				let data = {
					usertoken: this.usertoken,
					msg: this.userMsg
				}
				this.$store.commit("sendusermsg", JSON.stringify(data))
			},
			disconnect() {
				this.$store.commit("disconnect", "{}")
			}
		},
		computed: {
			spublicMsg() {
				return this.$store.state.publicMsg
			},
			suserMsg() {
				return this.$store.state.userMsg
			}
		}
	}
</script>

<style>
	.content {
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
	}

	.logo {
		height: 200rpx;
		width: 200rpx;
		margin-top: 200rpx;
		margin-left: auto;
		margin-right: auto;
		margin-bottom: 50rpx;
	}

	.text-area {
		display: flex;
		justify-content: center;
	}

	.title {
		font-size: 36rpx;
		color: #8f8f94;
	}
</style>
